package test0102;

import java.util.Arrays;

public class Platform {
    String platform;
    Order[]arr= new Order[10];
    int i =0;

    public Platform(String name) {
    }

    public Platform(String platform, Order[] arr, int i) {
        this.platform = platform;
        this.arr = arr;
        this.i = i;
    }



    public String getPlatform() {
        return platform;
    }

    public void setPlatform(String platform) {
        this.platform = platform;
    }

    public Order[] getArr() {
        return arr;
    }

    public void setArr(Order[] arr) {
        this.arr = arr;
    }

    public int getI() {
        return i;
    }

    public void setI(int i) {
        this.i = i;
    }

    @Override
    public String toString() {
        return "Platform{" +
                "platform='" + platform + '\'' +
                ", arr=" + Arrays.toString(arr) +
                ", i=" + i +
                '}';
    }

    public void add(Order o1) {
        if (i < arr.length) {
            arr[i] = o1;
            i++;
        } else {
            System.out.println("订单数组已满，无法添加更多订单！");
        }


    }

    public void printAll() {
        System.out.println("所有订单信息：");
        for (int j = 0; j < i; j++) {
            System.out.println(arr[j]);
        }
    }

    public Order findMaxOrder() {
        Order maxOrder = null;
        for (int j = 0; j < i; j++) {
            if (maxOrder == null || arr[j].getAmount() > maxOrder.getAmount()) {
                maxOrder = arr[j];
            }
        }
        return maxOrder;
    }

    public Order findMinOrder() {
        Order minOrder = arr[0]; // 假设至少有一个订单
        for (int j = 1; j < i; j++) {
            if (arr[j].getAmount() < minOrder.getAmount()) {
                minOrder = arr[j];
            }
        }
        return minOrder;
    }

    public Order findOrderByName(String bob) {
        for (int j = 0; j < i; j++) {
            if (arr[j].getCustomerName().equals(bob)) {
                return arr[j];
            }
        }
        return null;
    }

    public double calculateAverage() {
        double totalAmount = 0.0;
        for (int j = 0; j < i; j++) {
            totalAmount += arr[j].getAmount();
        }
        return i > 0 ? totalAmount / i : 0.0;
    }
}